package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysObject;
import com.ruoyi.system.service.ISysObjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品总览Controller
 * 
 * @author ruoyi
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/system/object")
public class SysObjectController extends BaseController
{
    @Autowired
    private ISysObjectService sysObjectService;

    /**
     * 查询物品总览列表
     */
    @PreAuthorize("@ss.hasPermi('system:object:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysObject sysObject)
    {
        startPage();
        List<SysObject> list = sysObjectService.selectSysObjectList(sysObject);
        return getDataTable(list);
    }

    /**
     * 导出物品总览列表
     */
    @PreAuthorize("@ss.hasPermi('system:object:export')")
    @Log(title = "物品总览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysObject sysObject)
    {
        List<SysObject> list = sysObjectService.selectSysObjectList(sysObject);
        ExcelUtil<SysObject> util = new ExcelUtil<SysObject>(SysObject.class);
        util.exportExcel(response, list, "物品总览数据");
    }

    /**
     * 获取物品总览详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:object:query')")
    @GetMapping(value = "/{objectId}")
    public AjaxResult getInfo(@PathVariable("objectId") Long objectId)
    {
        return success(sysObjectService.selectSysObjectByObjectId(objectId));
    }

    /**
     * 新增物品总览
     */
    @PreAuthorize("@ss.hasPermi('system:object:add')")
    @Log(title = "物品总览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysObject sysObject)
    {
        return toAjax(sysObjectService.insertSysObject(sysObject));
    }

    /**
     * 修改物品总览
     */
    @PreAuthorize("@ss.hasPermi('system:object:edit')")
    @Log(title = "物品总览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysObject sysObject)
    {
        return toAjax(sysObjectService.updateSysObject(sysObject));
    }

    /**
     * 删除物品总览
     */
    @PreAuthorize("@ss.hasPermi('system:object:remove')")
    @Log(title = "物品总览", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objectIds}")
    public AjaxResult remove(@PathVariable Long[] objectIds)
    {
        return toAjax(sysObjectService.deleteSysObjectByObjectIds(objectIds));
    }
}
